package com.harvest.scientific.ladder.util

import android.app.Activity
import android.graphics.Color
import android.os.Build
import android.view.View
import android.view.WindowManager

object StbarUtil {

    @JvmStatic
    fun setStatusBar(
        activity: Activity,
        darkContent: Boolean,
        statusBarColor: Int = Color.WHITE,
        translucent: Boolean
    ) {


        val window = activity.window
        val decorView = window.decorView
        var visibility = decorView.systemUiVisibility

        //请求系统 绘制状态栏的背景色
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        //这俩不能同时出现
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        window.statusBarColor = statusBarColor

        visibility = if (darkContent) {
            //白底黑字--浅色主题
            visibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
        } else {
            //黑底白字--深色主题
            // java  visibility &= ~ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            visibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
        }

        if (translucent) {
            //此时 能够使得页面的布局延伸到状态栏之下，但是状图兰的图标 也看不见了-,使得状图兰的图标 恢复可见性
            visibility =
                visibility or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        }
        decorView.systemUiVisibility = visibility
    }

}